<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
     <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">

</head>

<body class="gray-bg" style="color:#333;padding:3px;">
<div class="ibox">
    <div class="ibox-content">
        <table class="table table-bordered da_table white-bg" style="margin:10px 0">
            <tr>
                <td class="textR">经销商编号</td>
                <td>
                    {$sn}
                </td>
            </tr>
            <tr>
                <td class="textR">经销商名称</td>
                <td>{$title}</td>
            </tr>
            <tr>
                <td class="textR">现供货的系统</td>
                <td>
                    {$yiyou}
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="ibox">
    <div class="ibox-title text-center">请选择替换的经销商</div>
    <div class="ibox-content">
        <div class="row form-group">
            <div class="col-xs-5 col-xs-offset-3">
                <div class="input-group">
                    <input name="stuff" id="testNoBtn" type="text" placeholder="请输入关键字或空格查询" class=" form-control" value="">
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                        </ul>
                    </div>
                    <div class="renyuan" id="renyuan">
                    </div>
                </div>
            </div>
            <div>
                <a href="javascript:;" id="select" class="btn btn-sm btn-default" id="select">选择</a>
            </div>
        </div>
        <div class="row form-group">
            <form action="" id="add"></form>
            <div class="text-center padding-10" style="margin-top:10px"><a href="javascript:;"  class="btn btn-sm btn-primary" id="confirm">确认</a><span class="lr_5"></span><a href="javascript:;" class="btn btn-sm btn-warning" id="cancel">取消</a></div>
        </div>

    </div>
</div>
<!-- 全局js -->
{include file="Public/footer"}

<script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script>
    $(document).ready(function () {
        $('body').on('click','#renyuan .ren .close',function(){
            $(this).closest('.ren').remove()
        })
        $('#select').on('click',function () {
           var index = parent.layer.getFrameIndex(window.name);
            //iframe层-父子操作
            parent.layer.open({
                type: 2,
                title: '分区树',
                area: ['500px', '400px'],
                fixed: false, //不固定
                maxmin: true,
                content: '{:url("selectJXS")}?index='+index
            });
            return false

        })

        /**
         * 测试(首次从 URL 获取数据，显示 header，不显示按钮，忽略大小写，可清除)
         */
        $("#testNoBtn").bsSuggest({
            url: "{:url('provicejson')}",
            /*effectiveFields: ["userName", "shortAccount"],
            searchFields: [ "shortAccount"],*/
            effectiveFieldsAlias:{userName: "姓名"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword, data) {
            $(this).val('')
            $('#renyuan').html('<span class="ren" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
            //console.log('onSetSelectValue: ', keyword, data);
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });
        
        //确认
        $('#confirm').on('click',function () {
            var city = $('#renyuan .ren');
            var form = $('#add');
            if(!city.is('.ren')){
                top.swal('哈哈...',
                    '请选择要替换的城市!',
                    'error'
                )
            }else{
                var new1 = city.data('id')
                swal({
                        title: "确定要替换经销商吗？",
                        text: "该页面列出的所有系统所属经销商都会被替换！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定替换！",
                        closeOnConfirm: false
                    },
                    function(){
                        $.ajax({
                            type:'post',
                            url:form.attr('action'),
                            data:{new1:new1},
                            dataType:'json',
                            success:function (data) {
                                if(data.success==true){
                                    swal({title:"替换成功！", text:"所属经销商已经被替换。", type:"success"},function () {
                                        parent.history.go(0);
                                    });
                                }else{
                                    swal("替换失败！", data.msg, "error");
                                }
                            }
                        })

                    });
            }
        })
        $('#cancel').on('click',function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name))
        })
    })

</script>

</body>

</html>